package ControlLayer;

import java.util.ArrayList;

import DBLayer.DBDiscountGroup;
import DBLayer.IFDBDiscountGroup;
import ModelLayer.DiscountGroup;

public class DiscountGroupCtr {

	public DiscountGroupCtr() {

	}

	public DiscountGroup getGroup(int id) throws Exception {
		DiscountGroup dg = null;
		IFDBDiscountGroup dbDiscount = new DBDiscountGroup();
		dg = dbDiscount.getDiscount(id);
		if (dg != null) {
			return dg;
		} else {
			throw new PersonException("DiscountGroup is not found");
		}

	}

	public int createDg(String name, double discount) {
		DiscountGroup discountGroup = new DiscountGroup();
		discountGroup.setDiscount(discount);
		discountGroup.setName(name);
		IFDBDiscountGroup dbDiscount = new DBDiscountGroup();
		return dbDiscount.insertDiscount(discountGroup);
	}

	public int updateDg(int id, String name, double discount) {
		DiscountGroup dg = new DiscountGroup();
		dg.setId(id);
		dg.setName(name);
		dg.setDiscount(discount);

		IFDBDiscountGroup dbDiscount = new DBDiscountGroup();
		return dbDiscount.updateDiscount(dg);
	}

	public ArrayList<DiscountGroup> getAllDg() {
		IFDBDiscountGroup dbDiscount = new DBDiscountGroup();
		return dbDiscount.getAllDiscount();
	}

	public int deleteDg(int id) {
		IFDBDiscountGroup dbDiscount = new DBDiscountGroup();
		return dbDiscount.deleteDiscount(id);
	}

}
